fdbe_VerticalField

Got a function to create a 'field' but putting the label on top instead of to the side.

Looking for comments on this function, especially if there is a way to use contrained placement. Tried very hard but couldn't think of a way. Also I wonder if 'Vertical' is the right word.

Tried richFields but they won't line up right, always seem to cascade a little.

DB    VerticalField_dbPrevious  = null
DBE     VerticalField_dbePrevious       = null
 
//*****************************************************
DBE     fdbe_VerticalField(bool in_Adjacent, DB in_db, string in_Label, in_Initial, int in_Width, bool in_ReadOnly)
{     // Build a 'field' DBE such that the label is above the field rather than to the left.
        // Return the created 'field's DBE (e.g. for future 'get' and 'set' commands)
 
        // When in_Adjacent then ignore the current Simple Placement position 
        //      and instead put the new VerticalField next to the previous VerticalField on this dialog.
        // When not in_Adjacent then respect the current Simple Placement position.
        // The other input Parameters are the same as for the native 'field' command.
 
        // VerticalFields are useful to line up rows and columns of fields nicely
        //      without concern for the various lengths of Labels on those fields.
 
        // This technique requires two additional DBEs unknown to the calling program,
        //      The first is an Invisible field exactly same size as desired
        //      The second is a   visible label directly on top of the invisible field
        //      The real field is positioned below the invisible field.
 
        // This function is intended for Simple Placement.  Programs that wish Contrained Placement can awkwardly do this:
        // To Contrained the Placement OF this field:
        //      This is not supported as no method for doing so was found,
        //              although the caller using an invisible 'frame' worked some, but the label had
        //              to go inside and it didn't line up quite right.
        // To Constrain the Placement of other DBEs based ON this field:
        //      Get a handle of the invisible field above the live field by doing this right after the call:
        //              DBE dbeFieldLabel = VerticalField_dbePrevious
        //      Perform future horizontal placement based on that
 
        DBE     dbeField, dbeInvisible, dbeLabel
                                // We cannot actually do 'Adjacent' to previous VerticalField unless this DB
                                //      already has such a VerticalField
        bool    DoAdjacent      = in_Adjacent                                   and 
                                        (!null    VerticalField_dbePrevious)    and
                                        (in_db == VerticalField_dbPrevious)
 
                                // [1] Create Invisible DBE field at right spot, same size as desired field
        dbeInvisible = field(in_db, "", "", in_Width, true)
        hide(dbeInvisible)                      // Hide the temp field
 
        if (DoAdjacent)
        {  dbeInvisible ->"left" ->"flush"   ->VerticalField_dbePrevious
           dbeInvisible ->"top"  ->"aligned" ->VerticalField_dbePrevious
        }
        else
        {  //dbeInvisible ->"left" ->"form"
        }
           stacked(dbeInvisible)                        // dbeLabel goes on top
                                // [2] Create the visible Label, positioned right on top of the Invisible field
        dbeLabel        = label(in_db, in_Label)
                dbeLabel        ->"top"    ->"aligned"        ->dbeInvisible       // ?? This makes additional labels in the right horizontal spot
 
        if (DoAdjacent) //
        then dbeLabel   ->"left"   ->"spaced" ->VerticalField_dbePrevious  // Up against previous invis field
        else{}                         // leave label up against whatever is there
 
                                // [3] Finally create the desired field, positioned right below the invisible one
        dbeField        = field(in_db, "", in_Initial, in_Width, in_ReadOnly)
                dbeField ->"left" ->"aligned" ->dbeInvisible
                dbeField ->"top"  ->"flush"   ->dbeLabel
 
                                // [4] Remember 'Previous' for future 'Adjacent' requests, if any
        VerticalField_dbePrevious       = dbeInvisible
        VerticalField_dbPrevious        = in_db
 
        return(dbeField)
}     // end fdbe_VerticalField()
 
 
DB db
DBE dbe1, dbe2, dbe3, dbe4, dbe5, dbe6
 
 
void applyRead(DB dbXX)
{  infoBox((string get(dbe1)) "\n" (string get(dbe2)) "\n" (string get(dbe3)) "\n" (string get(dbe4)))
}
 
void    btnTemp(DBE dbeXX)
{    // some callback for this dialog
}
 
db      = create("ddd")
 
dbe1    = fdbe_VerticalField(true,  db, "Field1", "Field1Init", 20, true)   // Adjacent is ignored for this first DBE
dbe2    = fdbe_VerticalField(true,  db, "Field2", "Field2 Init", 30, false)
dbe3    = fdbe_VerticalField(true,  db, "Field3", "ddd", 40, false)
 
left(db)
 
dbe4  = fdbe_VerticalField(false, db, "Field4", "ddd", 40, false)
        beside(db)
 
dbe5    = toggle(db, "Toggle5", true)
        dbe5    ->"top"    ->"spaced" ->dbe2
                // Change to 'true' and it covers Toggle5:
 
dbe6  = fdbe_VerticalField(false, db, "Field6", "ddd", 10, false)
 
 
apply(db, "Read", applyRead)
realize(db, 100, 700)
show(db)

llandale - Thu Aug 25 17:06:04 EDT 2011

Re: fdbe_VerticalField
Mathias Mamsch - Fri Aug 26 08:47:06 EDT 2011

Hi Louie,

I know you do not like all that struct stuff and might not see the point, but I think the example attached shows
  • how to define custom DBEs (that consist of more than one Standard DBE)
  • how to enable contrained placement for them

The code does at the moment not support "bottom" and "right" glues, as long as you keep the placement "top" and "left" it should be fine. Hope the comments explain the most important parts, if you find bugs we can try to solve them. Hope that helps, Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Attachments

attachment_14676544_VerticalField.dxl

Re: fdbe_VerticalField
Mathias Mamsch - Fri Aug 26 08:51:18 EDT 2011

Mathias Mamsch - Fri Aug 26 08:47:06 EDT 2011
Hi Louie,

I know you do not like all that struct stuff and might not see the point, but I think the example attached shows

  • how to define custom DBEs (that consist of more than one Standard DBE)
  • how to enable contrained placement for them

The code does at the moment not support "bottom" and "right" glues, as long as you keep the placement "top" and "left" it should be fine. Hope the comments explain the most important parts, if you find bugs we can try to solve them. Hope that helps, Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

There is another thing to take into consideration. When you have a label and field and glue something to the left of it, then you probably need to know which one is larger. At the moment the code assumes that the field is larger and glues objects to the field. We could change that but I did not want to make the code unnecessary complex.

Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: fdbe_VerticalField
llandale - Mon Aug 29 10:45:31 EDT 2011

Mathias Mamsch - Fri Aug 26 08:51:18 EDT 2011
There is another thing to take into consideration. When you have a label and field and glue something to the left of it, then you probably need to know which one is larger. At the moment the code assumes that the field is larger and glues objects to the field. We could change that but I did not want to make the code unnecessary complex.

Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

You may very well drag me into the 1990s, but I sure you realize it will be kicking and screaming.

I didn't mean this clever stuff should be avoided altogether, just used sparingly. In this case you have the basis for a well defined set of functions that present a capability most folks will recognize in a manner easy for them to grasp; leaving the clever stuff mostly hidden.

So if this notion provided capability I would clean it up and deploy it; and make a small step towards my 'Renaissance'.

As for this example, I added stuff to the test dialog and things fall apart:

// ************** Test Dialog ************************
 
DB db = centered "Test"
 
VerticalField dbe1    = createVerticalField(db, "Field1", "Field1Init", 20, true)   // Adjacent is ignored for this first DBE
dbe1 -> "top" -> "form"
dbe1 -> "left" -> "form"
VerticalField dbe2      = createVerticalField(db, "Field2", "Field2 Init", 30, false)
dbe2 -> "top" -> "form" 
dbe2 -> "left" -> "spaced" -> dbe1 
 
DBE dbeT        = toggle(db, "Toggle", true) 
 
VerticalField dbe3      = createVerticalField(db, "Field3", "ddd", 40, false)
dbe3 -> "top"->"aligned" -> dbeT
dbe3 -> "left" -> "spaced" -> dbeT
 
// beside db
VerticalField dbe4      = createVerticalField(db, "Field4", "xxx", 30, false)
DBE dbeF        = field(db, "normalField", "aa", 20, true)
VerticalField dbe5      = createVerticalField(db, "Field5", "xxx", 30, false)
beside(db)
DBE dbeT2 = toggle(db, "Toggle2", false)
dbeT2 ->"left" ->"spaced" ->dbe5
left(db)
 
 
void myButtonCallback (DBE x) { ack "GLUED!" }
DBE myButton = button (db, "Glue me to teh field!", myButtonCallback) 
myButton -> "top" -> "spaced" -> dbe3
myButton -> "left" -> "spaced" -> dbe1
 
DBE dbeLab = label(db, "")
dbeLab ->"top" ->"spaced" ->dbe5
 
// realize(db, 100, 700)
show(db)


There remains the problem of lining up the field with the exact left hand side of the label, without knowing which DBE is supposed to be on its left.

As for which is wider, label or field, I think you'd need to know the default font and do really clever width comparison's which does not seem realistic; presuming the Field is longer is a reasonable restriction.

I don't do Frames or Canvases, but I wonder if the 'label' and the 'field' positioned in one would work, where positioning is done completely to-and-from the Frame/Canvas DBE.

Too bad there is no "WhereIsSimplePlacement" command that returns the most recent DBE handle and whether we are currently "left", "beside", "below" or whatever.

 

 

  • Louie